<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  <meta name="author" content="火星科技 http://mars3d.cn ">
  <meta name="apple-touch-fullscreen" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no">
  <meta name="x5-fullscreen" content="true">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  <!-- 标题及搜索关键字 -->
  <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  <meta name="description"
        content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS" />

  <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico">
  <title>三维地图 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>


  <!--第三方lib-->
  <script type="text/javascript" src="../lib/include-lib.js" libpath="../lib/" include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d"></script>

  <link href="css/style.css" rel="stylesheet" />
</head>

<body class="dark">
  <!--加载前进行操作提示，优化用户体验-->
  <div id="mask" class="signmask" onclick="removeMask()"></div>

  <div id="mars3dContainer" class="mars3d-container"></div>


  <!-- 面板 -->
  <div class="infoview">

    <input id="btnSelPoint" type="button" class="btn btn-primary" value="追踪目标点" />
  </div>

  <!-- 图层管理相关处理js -->
  <script type="text/javascript" src="./js/graphicManager.js"></script>


  <script src="./js/common.js"></script>
  <script type="text/javascript">
    'use script' //开发环境建议开启严格模式

    var map

    function initMap(options) {
      //合并属性参数，可覆盖config.json中的对应配置
      var mapOptions = mars3d.Util.merge(options, {
        scene: {
          center: { lat: 30.758571, lng: 116.426699, alt: 23428, heading: 347, pitch: -40 },
        },
      })

      //创建三维地球场景
      map = new mars3d.Map('mars3dContainer', mapOptions)

      //创建矢量数据图层
      var graphicLayer = new mars3d.layer.GraphicLayer()
      map.addLayer(graphicLayer)

      //图层管理的相关处理，代码在\js\graphicManager.js
      initLayerManager(graphicLayer)

      //加一些演示数据
      addGraphic_01(graphicLayer)
      addGraphic_02(graphicLayer)
      addGraphic_03(graphicLayer)
    }

    //静态的位置
    function addGraphic_01(graphicLayer) {
      var coneTrack = new mars3d.graphic.ConeTrack({
        position: [116.327881, 31.018378, 5000],
        targetPosition: [116.311135, 30.998408, 1264.9], //可选
        style: {
          slices: 4, //四凌锥
          // length: 4000,//targetPosition存在时无需传
          angle: 5, //半场角度
          color: '#ff0000',
          opacity: 0.4,
        },
      })
      graphicLayer.addGraphic(coneTrack)
    }

    //静态的位置
    function addGraphic_02(graphicLayer) {
      let position = [116.28782, 30.971557, 5000]
      //加个飞机
      var primitive = new mars3d.graphic.ModelPrimitive({
        position: position,
        style: {
          url: 'http://data.marsgis.cn/gltf/mars/feiji.glb',
          scale: 1,
          minimumPixelSize: 50,
        },
      })
      graphicLayer.addGraphic(primitive)

      //圆锥追踪体
      var coneTrack = new mars3d.graphic.ConeTrack({
        position: position,
        // targetPosition: [116.317411, 30.972581, 1439.7], //可选
        style: {
          length: 4000,
          angle: 5, //半场角度
          material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.CircleWave, {
            duration: 2000,
            color: '#02ff00',
          }),
        },
      })
      graphicLayer.addGraphic(coneTrack)

      $('#btnSelPoint').click(function () {
        map.graphicLayer.startDraw({
          type: 'point',
          style: {
            pixelSize: 8,
            color: '#ffff00',
          },
          success: function (graphic) {
            var position = graphic.positionShow
            map.graphicLayer.clear()

            coneTrack.targetPosition = position
          },
        })
      })
    }

    //动态的位置
    function addGraphic_03(graphicLayer) {
      let propertyFJ = getSampledPositionProperty([
        [116.364307, 31.03778, 5000],
        [116.42794, 31.064786, 5000],
        [116.474002, 31.003825, 5000],
        [116.432393, 30.951142, 5000],
        [116.368497, 30.969006, 5000],
        [116.364307, 31.03778, 5000],
      ])

      //飞机
      var graphicModel = new mars3d.graphic.ModelEntity({
        position: propertyFJ,
        orientation: new Cesium.VelocityOrientationProperty(propertyFJ),
        style: {
          url: 'http://data.marsgis.cn/gltf/mars/zhanji.glb',
          scale: 0.3,
          minimumPixelSize: 30,
        },
      })
      graphicLayer.addGraphic(graphicModel)

      //汽车
      let propertyQC = getSampledPositionProperty([
        [116.391268, 30.956038, 827.2],
        [116.37934, 30.980835, 898.1],
        [116.382514, 30.999031, 921.5],
        [116.40338, 31.009258, 1214],
        [116.412254, 31.021635, 1224.1],
        [116.432328, 31.045508, 804.3],
      ])
      var graphicQC = new mars3d.graphic.PathEntity({
        position: propertyQC,
        orientation: new Cesium.VelocityOrientationProperty(propertyQC),
        style: {
          width: 1,
          color: '#ffff00',
          opacity: 0.4,
          leadTime: 0,
        },
        model: {
          url: 'http://data.marsgis.cn/gltf/mars/qiche.gltf',
          scale: 0.5,
          minimumPixelSize: 50,
        },
      })
      graphicLayer.addGraphic(graphicQC)

      //圆锥追踪体（动态position=>动态targetPosition）
      var coneTrack = new mars3d.graphic.ConeTrack({
        position: propertyFJ,
        targetPosition: propertyQC,
        style: {
          // length: 4000, //targetPosition存在时无需传
          angle: 1, //半场角度
          color: '#00ffff',
          opacity: 0.4,
        },
      })
      graphicLayer.addGraphic(coneTrack)
    }

    //计算演示的SampledPositionProperty轨迹
    function getSampledPositionProperty(points) {
      let property = new Cesium.SampledPositionProperty()

      let start = map.clock.currentTime
      let positions = mars3d.LatLngArray.toCartesians(points)
      for (let i = 0; i < positions.length; i++) {
        let time = Cesium.JulianDate.addSeconds(start, i * 20, new Cesium.JulianDate())
        let position = positions[i]
        property.addSample(time, position)
      }
      return property
    }
  </script>
</body>

</html>
